package com.ctsi.auth.integration.authenticator.impl;

import com.ctsi.auth.integration.IntegrationAuthentication;
import com.ctsi.auth.integration.authenticator.AbstractPreparableIntegrationAuthenticator;
import com.ctsi.commons.util.UtilValidate;
import com.ctsi.organise.common.api.OrganiseFactoryBean;
import com.ctsi.organise.common.model.UserLogin;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.stereotype.Component;

/**
 * @author zhangjw
 * @className UsernamePasswordAuthenticator
 * @description 默认用户名密码登陆
 * @date 2019/2/21 18:48
 **/
@Component
public class UsernamePasswordAuthenticator extends AbstractPreparableIntegrationAuthenticator {

    @Override
    public UserLogin authenticate(IntegrationAuthentication integrationAuthentication) {
        String username = integrationAuthentication.getUsername();
        UserLogin userlogin = OrganiseFactoryBean.getInstance().getUserLoginProxy().findUserLoginByLoginName(username);
        return userlogin;
    }

    @Override
    public void prepare(IntegrationAuthentication integrationAuthentication) throws OAuth2Exception {

    }

    @Override
    public boolean support(IntegrationAuthentication integrationAuthentication) {
        return UtilValidate.isEmpty(integrationAuthentication.getAuthType());
    }
}
